import sugar, unittest
import nellypkg/types

suite "values":

  test "wrapping and unwrapping":
    check 42.initBigInt.jelly.intVal == 42.initBigInt
    check 42.jelly.intVal == 42.initBigInt
    check 42.0.jelly.floatVal == 42.0
    check "foo".jelly.strVal == "foo"
    check @[42, 43, 44, 45].jelly.list[2].intVal == 44

  test "reference semantics for lists":
    let
      a = @[42].jelly
      b = a
    a.list[0] = 43.jelly
    check b.list[0].intVal == 43
    b.list[0] = 44.jelly
    check a.list[0].intVal == 44

  test "value equality and inequality":
    check 42.jelly == 42.jelly
    check 42.jelly != 43.jelly
    check 42.0.jelly == 42.0.jelly
    check 42.0.jelly != 43.0.jelly
    check "foo".jelly == "foo".jelly
    check "foo".jelly != "bar".jelly
    check @[42, 43].jelly == @[42, 43].jelly
    check @[42, 43].jelly != @[42, 44].jelly
    check 42.jelly != 42.0.jelly
    check "foo".jelly != @["f", "o", "o"].jelly

suite "links":

  test "creating and calling links":
    check toJellyLink(() => 42.jelly)().intVal == 42
    check toJellyLink((z: JellyVal) => (z.intVal + 42).jelly)(43.jelly).intVal == 85
    check toJellyLink((x, y: JellyVal) => (x.intVal + y.intVal).jelly)(42.jelly, 43.jelly).intVal == 85
